unit UnitMainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TBXSwitcher, ImgList, TBXStatusBars, TBX, TB2Item, TB2Dock,
  TB2Toolbar, GradientTabSet, UnitBaseFrame, ActnList, GSPDB, UnitGlobal,
  IniFiles;

type
  TCategoryPanelGroup = class(ExtCtrls.TCategoryPanelGroup)
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  end;

  TFormMain = class(TForm)
    gtsTabSet: TGradientTabSet;
    TBXDock1: TTBXDock;
    TBXSwitcher1: TTBXSwitcher;
    TBXStatusBar1: TTBXStatusBar;
    TBXToolbar1: TTBXToolbar;
    TBXSubmenuItem1: TTBXSubmenuItem;
    TBXItem1: TTBXItem;
    TBXItem3: TTBXItem;
    ActionList1: TActionList;
    procedure FormShow(Sender: TObject);
    procedure gtsTabSetGetImageIndex(Sender: TObject; TabIndex: Integer;
      var ImageIndex: Integer);
    procedure gtsTabSetChange(Sender: TObject);
  private
    FINI: TIniFile;
    procedure FrameNotify(Sender: TObject; NotifyType: TNotifyType; Data: Pointer);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure AddFrames(AClasses: array of TFrameBaseClass);
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

constructor TFormMain.Create(AOwner: TComponent);
begin
  inherited;
  Font.Name := Screen.MessageFont.Name;
  FINI := TIniFile.Create(ChangeFileExt(Application.ExeName, extIni));
  gtsTabSet.Tabs.Clear;
end;

destructor TFormMain.Destroy;
begin
  FINI.Free;
  inherited;
end;

procedure TFormMain.FormShow(Sender: TObject);
begin
  gtsTabSet.Scroller.Visible := False;
  if gtsTabSet.Tabs.Count > 0 then
    gtsTabSet.TabIndex := 0;
end;

procedure TFormMain.FrameNotify(Sender: TObject; NotifyType: TNotifyType;
  Data: Pointer);
begin
  //FrameNotify
end;

procedure TFormMain.AddFrames(AClasses: array of TFrameBaseClass);
var
  I: Integer;
  oFrame: TFrameBase;
begin
  for I := Low(AClasses) to High(AClasses) do
  begin
    oFrame := AClasses[I].Create(Self);
    oFrame.OnNotify := FrameNotify;
    oFrame.Visible := False;
    oFrame.Parent := gtsTabSet;
    oFrame.Align := alClient;
    gtsTabSet.Tabs.AddObject(oFrame.Caption, oFrame);
  end;
end;

procedure TFormMain.gtsTabSetChange(Sender: TObject);
var
  I: Integer;
  oFrame: TFrameBase;
begin
  for I := 0 to gtsTabSet.Tabs.Count - 1 do
  begin
    oFrame := TFrameBase(gtsTabSet.Tabs.Objects[I]);
    if Assigned(oFrame) then
      oFrame.Visible := gtsTabSet.TabIndex = I;
  end;
end;

procedure TFormMain.gtsTabSetGetImageIndex(Sender: TObject;
  TabIndex: Integer; var ImageIndex: Integer);
var
  oFrame: TFrameBase;
begin
  oFrame := TFrameBase(gtsTabSet.Tabs.Objects[TabIndex]);
  if Assigned(oFrame) then
    ImageIndex := oFrame.ImageIndex
  else
    ImageIndex := -1;
end;

{ TCategoryPanelGroup }

procedure TCategoryPanelGroup.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
    Style := Style xor WS_BORDER;
end;

end.
